<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>pdfgmm.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>y&nbsp;</span>=&nbsp;<span class=defun_name>pdfgmm</span>(<span class=defun_in>X,&nbsp;model&nbsp;</span>)<br>
<span class=h1>%&nbsp;PDFGMM&nbsp;Evaluates&nbsp;gaussian&nbsp;mixture&nbsp;model.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;y&nbsp;=&nbsp;pdfgmm(X,&nbsp;model&nbsp;)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;This&nbsp;function&nbsp;evaluates&nbsp;a&nbsp;probability&nbsp;density&nbsp;function&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;determined&nbsp;by&nbsp;Gaussian&nbsp;mixture&nbsp;model&nbsp;(GMM)&nbsp;for&nbsp;given&nbsp;input&nbsp;column&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;vectors&nbsp;in&nbsp;X.&nbsp;The&nbsp;GMM&nbsp;is&nbsp;defined&nbsp;as</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;y(i)&nbsp;=&nbsp;sum&nbsp;model.Prior(j)*pdfgauss(X(:,i),model.Mean(:,j),model.Cov(:,:,j))</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j=1:ncomp</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;for&nbsp;all&nbsp;i=1:size(X,2).</span><br>
<span class=help>%&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;X&nbsp;[dim&nbsp;x&nbsp;num_data]&nbsp;Input&nbsp;matrix&nbsp;of&nbsp;column&nbsp;vectors.</span><br>
<span class=help>%&nbsp;&nbsp;model.Mean&nbsp;[dim&nbsp;x&nbsp;ncomp]&nbsp;Means&nbsp;of&nbsp;Gaussians.</span><br>
<span class=help>%&nbsp;&nbsp;model.Cov&nbsp;[dim&nbsp;x&nbsp;dim&nbsp;x&nbsp;ncomp]&nbsp;Covarince&nbsp;matrices.</span><br>
<span class=help>%&nbsp;&nbsp;model.Prior&nbsp;[ncomp&nbsp;x&nbsp;1]&nbsp;Weights&nbsp;of&nbsp;components.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;y&nbsp;[1&nbsp;x&nbsp;num_data]&nbsp;Values&nbsp;of&nbsp;probability&nbsp;density&nbsp;function.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;Univariate&nbsp;case</span><br>
<span class=help>%&nbsp;&nbsp;x&nbsp;=&nbsp;linspace(-5,5,100);</span><br>
<span class=help>%&nbsp;&nbsp;distrib&nbsp;=&nbsp;struct('Mean',[-2&nbsp;3],'Cov',[1&nbsp;0.5],'Prior',[0.4&nbsp;0.6]);</span><br>
<span class=help>%&nbsp;&nbsp;y&nbsp;=&nbsp;pdfgmm(x,distrib);</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;plot(x,y);</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;Multivariate&nbsp;case</span><br>
<span class=help>%&nbsp;&nbsp;model.Mean(:,1)&nbsp;=&nbsp;[-1;-1];&nbsp;model.Cov(:,:,1)&nbsp;=&nbsp;[1,0.5;0.5,1];&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;model.Mean(:,2)&nbsp;=&nbsp;[1;1];&nbsp;model.Cov(:,:,2)&nbsp;=&nbsp;[1,-0.5;-0.5,1];&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;model.Prior&nbsp;=&nbsp;[0.4&nbsp;0.6];</span><br>
<span class=help>%&nbsp;&nbsp;[Ax,Ay]&nbsp;=&nbsp;meshgrid(linspace(-5,5,100),&nbsp;linspace(-5,5,100));</span><br>
<span class=help>%&nbsp;&nbsp;y&nbsp;=&nbsp;pdfgmm([Ax(:)';Ay(:)'],model);</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;surf(&nbsp;Ax,&nbsp;Ay,&nbsp;reshape(y,100,100));&nbsp;shading&nbsp;interp;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;GMMSAMP,&nbsp;PDFGAUSS.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;28-apr-2004,&nbsp;VF</span><br>
<br>
<hr>
<span class=comment>%&nbsp;allows&nbsp;inputs&nbsp;to&nbsp;be&nbsp;given&nbsp;in&nbsp;cell&nbsp;array</span><br>
model&nbsp;=&nbsp;c2s(model);<br>
<br>
y&nbsp;=&nbsp;model.Prior(:)'*pdfgauss(X,model);<br>
<br>
<span class=jump>return</span>;<br>
</code>
